﻿@model work_dynamic
<script src="@Url.Content("~/Scripts/xheditor/xheditor-1.1.14-zh-cn.min.js")" type="text/javascript"   charset="utf-8" ></script>
@using (Html.BeginForm("Edit", "Work", Html.ViewContext.RouteData.Values, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(a=>a.id)
    <div id="edit-car" style="width:900px;margin:5px 5px 5px 5px">

        <table class="edit-table">
            <tr>
                <td style="width: 120px; text-align: right;">*主标题：</td>
                <td>@Html.TextBoxFor(a=>a.title)</td>
            </tr>
            <tr>
                <td style="width: 120px; text-align: right;">副标题：</td>
                <td>@Html.TextBoxFor(a=>a.title2)</td>
            </tr>

            <tr>
                <td style="width: 120px; text-align: right">*图片：</td>
                <td><input type="file" name="fileImage" id="fileImage" style="width:100%" /></td>
            </tr>
            <tr>
                <td style="width: 120px; text-align: right">图片2：</td>
                <td><input type="file" name="fileImage2" id="fileImage2" style="width:100%" /></td>
            </tr>
            <tr>
                <td style="width: 120px; text-align: right">图片3：</td>
                <td><input type="file" name="fileImage3" id="fileImage3" style="width:100%" /></td>
            </tr>

            <tr>
                <td style="width: 120px; text-align: right">是否生效：</td>
                <td>@Html.CheckBoxFor(a=>a.is_use)</td>
            </tr>
            <tr>
                <td style="width: 120px; text-align: right;">*详细内容：</td>
                <td colspan="3">
                    @*<textarea id="elm3" name="elm3" class="xheditor-simple" rows="25" cols="80" style="width: 100%">
                     </textarea>*@
                    @Html.TextAreaFor(a => a.html_content,25,30,new { @style = "width: 100%;",@class="xheditor-mfull" })

                </td>
            </tr>

        </table>
        <br />
        <div class="validation-errors">@ViewBag.ErrorMessage</div>
    </div>
    <table style="width:900px">
        <tr>
            <td style="width:850px"></td>
            <td>
                @Html.DevExpress().Button(settings =>
                {
                    settings.Name = "Button1";
                    settings.Text = "保存";
                    //settings.Enabled = CurrentUser.CheckPermission(PermissionManager.填写GPS统计表);
                    settings.UseSubmitBehavior = false;
                    settings.Width = 70;
                    settings.ControlStyle.CssClass = "button1";
                    settings.ClientSideEvents.Click = "function(s, e){ commit_data();}";
                }).GetHtml()

            </td>
            <td>
                @Html.DevExpress().Button(settings =>
                {
                    settings.ControlStyle.CssClass = "button2";
                    settings.Name = "Button2";
                    settings.Text = "取消";
                    settings.Width = 70;
                    settings.ClientSideEvents.Click = "function(s, e){ location.href='" + @Url.Action("List", "Work") + "' }";
                }).GetHtml()
            </td>
        </tr>

    </table>
    
    <script type="text/javascript">
        $(function () {
            $('#html_content').xheditor({ tools: 'simple' });
        });
        
        function commit_data() {
            var allow_ext = "jpg|jpeg|gif|bmp|";
            var t=$("#title").val();
            if (t == null || t == "") {
                alert("请输入标题。");
                return;
            }
            if (t.indexOf("'") >= 0 || t.indexOf("\"") >= 0) {
                alert("标题不能带有引号。");
                return;
            }
            var file = $("#fileImage").val();
            var id = $("#id").val();

            if (id == 0) {
                if (file == null || file == "") {
                    alert("请选择要上传的文件。");
                    return;
                }
            }
            if (!check_file("fileImage", allow_ext,2048)) return;
            
            if (!check_file("fileImage2", allow_ext, 2048)) return;
            if (!check_file("fileImage3", allow_ext, 2048)) return;


            if ($("#html_content").val() == null || $("#html_content").val() == "") {
                alert("请输入内容。");
                return;
            }
            
            document.forms[0].submit();
        };
    </script>
}